package fileutil

import (
	"io"
	"os"
)

const BUFFER_SIZE = 8192

func CopyFile(fromPath, toPath string) (result bool) {
	defer func() {
		if e := recover(); nil != e {
			result = false
		}
	}()

	source, _ := os.Open(fromPath)
	defer source.Close()
	dest, _ := os.Create(toPath)
	defer dest.Close()
	io.CopyBuffer(dest, source, make([]byte, BUFFER_SIZE))
	return true
}

// ExistsWithType 路径是否存在
// bool 是否存在
// bool true-文件 false-目录
func ExistsWithType(path string) (bool, bool) {
	stat, err := os.Stat(path)
	if nil == err {
		if stat.IsDir() {
			return true, false
		}
		return true, true
	}
	return false, false
}

// Exists 路径是否存在
func Exists(path string) bool {
	exists, _ := ExistsWithType(path)
	return exists
}
